package it.crudity.web.util;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

public class BeanPropertyMapFactory {

	public static Map<String, Object> getBeanPropertyMap(String[] props, Object bean) throws IllegalAccessException,
			InvocationTargetException, NoSuchMethodException {
		if (bean == null)
			return null;

		Map<String, Object> propMap = new HashMap<String, Object>();
		for (String propertyName : props) {
			Object prop = BeanUtils.getProperty(bean, propertyName);
			propMap.put(propertyName, prop);
		}

		return propMap;
	}
}
